package com.gxa.controller.discrepancy;

import com.gxa.common.utils.R;
import com.gxa.entity.discrepancy.ComingVisitor;
import com.gxa.service.discrepancy.ComingVisitorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description:预约  即将到访人
 * @Author: zhuiyi
 * @CreatTime: 2022/10/19 8:43
 **/
@RestController
@Api(tags = "访客管理--->访客审核(预约，即将到访)")
@RequestMapping("/coming")
public class ComingVisitorController {
    @Autowired
    private ComingVisitorService service;

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("查询所有预约者")
    @GetMapping("/list")
    public R queryAll(){
        List<ComingVisitor> comingVisitors = service.getBaseMapper().selectList(null);
        return R.ok().put("data",comingVisitors);
    }

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("添加预约者")
    @PostMapping("/add")
    public R add(@RequestBody ComingVisitor visitor){
        if(service.save(  visitor)){
            return R.ok("添加成功！");
        }
        return R.error();
    }

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("删除预约者")
    @DeleteMapping("/del/{id}")
    public R add(@PathVariable("id") Integer id){
        if(service.removeById(id)){
            return R.ok("删除成功！");
        }
        return R.error("del error");
    }
    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("编辑预约者")
    @GetMapping("/update")
    public R update(@RequestBody ComingVisitor visitor){
        if(service.updateById(visitor)){
            return R.ok("更新成功！");
        }
        return R.error("update error");
    }

}
